<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
import Edit from "./../edit/index";
export default {
    mixins: [
        Vue.prototype.$vFN.Mixins.Base,
        Vue.prototype.$vFN.Mixins.Page,
        Vue.prototype.$vFN.Mixins.Table,
    ],
    components: {
        SelectDataGoods: async () =>
            Vue.extend(await Vue.prototype.$vFN.Components.Base.SelectDataGoods()),
    },
    data() {
        return {
            appWindow: window,
            // 页面接口地址
            apiUrl: {
                list: "plugin/distribution/backend/goods/index",
                delete: "admin/category/del",
            },
            // 表格查询数据
            mixinTable_tableSearchData: {
                name: "",
            },
            // 表格数据
            tableData: [],
            // 表格数据删除展示结构
            tableDeleteConfig: {
                columns: [
                    {
                        label: "分类名称",
                        prop: "name",
                        type: "",
                    },
                    {
                        label: "绑定门店数",
                        prop: "count",
                        type: "",
                    },
                ],
            },
            goodsIds: [],
        };
    },
    methods: {
        async addProduct() {
            this.goodsIds = [];
            this.$vFN.Directives.SelectDataGoods({
                appWindow: this.appWindow,
                selectIds: this.goodsIds,
                apiConfig:this.$vFN.Tools.getAppGlobalData("componentsApiConfig.SelectDataGoods",this.appWindow),
                onSuccess: (res) => {
                    // console.error(res, "1243242414214");
                    this.goodsIds = res;
                    this.getProduct()
                },
            });
        },
        async getProduct() {
            let res = await this.$vFN.Http.post({
                url: "plugin/distribution/backend/goods/add",
                data: {
                    product_ids: this.goodsIds,
                }
            },window)
            if(res.code == 200) {
                this.mixinTable_refreshData();
                this.$vFN.Tools.messageSuccess("操作成功");
            }
        },
        async pass(params_) {
            this.$confirm("确定进行此操作吗？", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                // type: "error",
                dangerouslyUseHTMLString: true,
            }).then(async () => {
                let res = await this.$vFN.Http.post({
                    url: "admin/withdraw/pass",
                    data: {
                        id: params_.id,
                    },
                },window);
                this.mixinTable_refreshData();
                if (res.code == 200) {
                    this.$vFN.Tools.messageSuccess("操作成功");
                }
            }).catch(() => {});
        },
        async participate(product_id,type) {
            this.$confirm("确定进行此操作吗？", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                // type: "error",
                dangerouslyUseHTMLString: true,
            }).then(async () => {
                let res = await this.$vFN.Http.post({
                    url: "plugin/distribution/backend/goods/toggleStatus",
                    data: {
                        product_id: product_id,
                        join_status: type,
                    }
                },window);
                if (res.code == 200) {
                    this.mixinTable_refreshData();
                    this.$vFN.Tools.messageSuccess("操作成功");
                }
            }).catch(() => {});
            // let res = await this.$vFN.Http.post({
            //     url: "plugin/distribution/backend/goods/toggleStatus",
            //     data: {
            //         product_id: product_id,
            //         join_status: type,
            //     }
            // },window);
        },
        // 打开添加/修改
        editBoxOpen(params_) {
            Edit.init({
                // mixinEdit_parent: this,
                // mixinEdit_editType: params_.type,
                product_id: params_.product_id,
                onSuccess:() => {
                    this.mixinTable_refreshData();
                }
            });
        },
        // 初始化
        async init() {
            console.log(this.mixinTable_tableData, 2);
            this.mixinTable_refreshData();
        },
    },
    mounted() {
        this.init();
    },
    activated() {},
};
</script>